import asyncio


async def coroutine_example(number):
    # 模拟耗时操作
    print(f"Coroutine {number} begin")
    await asyncio.sleep(3)
    print(f"Coroutine {number} finished")


async def main():
    # 创建协程列表
    coroutines = [coroutine_example(number) for number in range(100)]

    # 创建协程池的大小
    semaphore = asyncio.Semaphore(3)

    # 在协程池中运行所有协程
    await asyncio.wait([asyncio.shield(semaphore.acquire())])
    await asyncio.gather(*coroutines)
    semaphore.release()


# 运行事件循环
asyncio.run(main())